import { getToken ,getUserInfo,removeToken,removeUserInfo } from '@/utils/auth'
import { ElMessage } from 'element-plus'
export default defineNuxtRouteMiddleware((to, from) => {
  console.log('to:',to)
  if(to.name ==='beVip' || to.name ==='members'){
    let userInfo = getUserInfo()
    let token = getToken()
    if(token && userInfo && userInfo.role ==='admin'){
      return true
    }else {
      ElMessage({
        type: 'error',
        message: '权限不足'
      })
      removeToken()
      removeUserInfo()
      return navigateTo('/login')
    }
  }
});